package com.young.filesystem.task;

import com.young.filesystem.service.FileUploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Slf4j
@Configuration
@EnableScheduling
public class ScheduleTask {

    private final FileUploadService fileUploadService;

    public ScheduleTask(@Autowired FileUploadService fileUploadService) {
        log.info("初始化了定时清理文件任务！");
        this.fileUploadService = fileUploadService;
    }

    @Scheduled(cron = "0 0 0 1 * ?")
    private void checkExpiredFile() {
        log.info("开始清理过期文件！");
        fileUploadService.deleteFile();
        log.info("结束清理过期文件！");
    }
}
